#include <EB0/EB0.h>

namespace EB0
{
namespace States
{
#pragma region Constructor / Destructor
	// Constructor
	TitleScreen::TitleScreen()
	{
		// Null pointers
		mTitleBGM = 0;
	}

	// Destructor
	TitleScreen::~TitleScreen()
	{
		// Null pointers
		mTitleBGM = 0;
	}
#pragma endregion

#pragma region Load / Unload
	// Load resources
	void TitleScreen::load(Window::RenderWindow* window)
	{
		// Load new music
		mTitleBGM = Managers::AudioManager::getSingletonPtr()->createMusic("music/06_time_passage.ogg");

		// Load opening screens
		createSlide("graphics/titlescreen1.png", 6.0f, true);
		createSlide("graphics/titlescreen2.png", 6.0f, true);
		createSlide("graphics/title.png", 0.0f, true); // await user input for a skipForward()
		createSlide("graphics/titlescreen3.png", 12.0f, true); // was false
		createSlide("graphics/titlescreen4.png", 8.0f, true); // was false
		createSlide("graphics/titlescreen5.png", 12.0f, true); // was false
		createSlide("graphics/titlescreen6.png", 8.0f, true); // was false
		createSlide("graphics/titlescreen7.png", 12.0f, true);  // was false; hold a bit longer as we're ending...
		createSlide("graphics/Sample.png", 0.0f, true); // just a sample screenshot of the game

		// Load the slideshow
		loadSlideshow(window);
	}

	// Unload resources
	void TitleScreen::unload(Window::RenderWindow* window)
	{
		// Unload slideshow
		unloadSlideshow(window);

		// Unload any previous music
		if (mTitleBGM)
			Managers::AudioManager::getSingletonPtr()->destroyMusic(mTitleBGM);
	}
#pragma endregion

#pragma region Create / Destroy Scene
	// Create scene
	void TitleScreen::createScene(Window::RenderWindow* window)
	{
		// Play music
		if (mTitleBGM)
		{
			mTitleBGM->Play();
			mTitleBGM->SetLoop(true);
		}

		// Set the background colour of the window to black
		if (window)
			window->setClearColor(0, 0, 0);

		// Create slideshow scene
		createSlideshowScene(window);
	}

	// Destroy scene
	void TitleScreen::destroyScene(Window::RenderWindow* window)
	{
		// Unload slideshow scene
		destroySlideshowScene(window);

		// Stop music
		if (mTitleBGM)
			mTitleBGM->Stop();
	}
#pragma endregion

#pragma region Update State
	// Update state
	void TitleScreen::update(Window::RenderWindow* window, float dt)
	{
		// Update slideshow, switch to world state if no slides remain
		if (!updateSlideshow(window, dt))
			changeState(EB0::States::gThePlace);
	}
#pragma endregion
} // namespace States
}